<template>
    <div>
        <div v-if='engine==0'>
            <Engine @openEngine='openEngine'></Engine>
        </div>
        <div style='background: #fff' v-else>
            <div class='content-title'>错误列表</div>
            <div style='padding:35px 20px'>
                <div style="padding:1px">
                    <Table :columns="debugList" :data="debugData" stripe></Table>
                </div>
                <div style='overflow: hidden'>
                    <Page :total="pagination.rowCount" :page-size='pagination.pageSize' @on-change='changePage' style='float: right;margin: 20px 0;'></Page>
                </div>
            </div>
            <Modal v-model="modal" width="600">
                <p slot="header">
                    <span>信息</span>
                </p>
                <div style='background:#fffce6;padding:10px;color:#6f5125'>
                    {{detail}}
                </div>
                <div slot="footer" style='margin-top: 24px'>
                    <button class='btn-sure' @click="cancel">确认</button>
                </div>
            </Modal>
        </div>
    </div>
</template>
<script type="text/javascript">
	import Engine from './engine.vue'
    export default{
        components:{
            Engine
        },
		data(){
			return{
                engine:1,
				debugList: [
                    {
                        title: '类型',
                        key: 'type'
                    },
                    {
                        title: '名称',
                        key: 'name'
                    },
                    {
                        title: '信息',
                        key: 'info',
                        render: (h, params) => {
                            return h('div', [
                                h('span', {
                                    style: {
                                        color:'#06A0FD',
                                        cursor:'pointer'
                                    },
                                    on: {
                                        click: () => {
                                            this.moreInfo(params.row)
                                        }
                                    }
                                }, '点击查看')
                            ]);
                        }
                    },
                    {
                        title: '详情',
                        key: 'message',
                        
                    },
                    {
                        title: '设备',
                        key: 'device'
                    },
                    {
                        title: '系统',
                        key: 'system'
                    },
                    {
                        title: '备注',
                        key: 'remark'
                    },
                    {
                        title: '创建时间',
                        key: 'created_at',
                        width:110,
                        render: (h, params) => {
                            return h('span', this.format(params.row.created_at))
                        }
                    },
                ],
                debugData: [],
                pagination:{},
                modal:false,
                detail:''
			}
		},
        created(){
            this.$bus.emit('updateMainMenuActive',this.$route.fullPath);
            this.getData();
        },
		methods:{
            getData(page){
                let url = '/home/app/engine/debug';
                if(page){
                    url += '?page=' +page;
                }
                this.fetch(url).then(res=>{
                    if(res&&res.data.data&&res.data.code){
                        this.debugData = res.data.data.data;
                        this.pagination = res.data.data.pagination;
                        this.engine = res.data.data.engine;
                    }
                })
            },
            changePage(page){
                this.getData(page);
            },
            //开通云引擎
            openEngine(){
                this.fetch('/home/app/engine/switch?engine=1').then(res=>{
                    if(res&&res.data.data){
                        this.getData();
                    }
                })
            },
			moreInfo(row){
                this.modal = true;
                this.detail = row.info;
            },
            cancel(){
                this.modal = false;
            }
		}
	}
</script>
